package com.waya.demo.queue;

import java.util.concurrent.BlockingQueue;

public class Consumer implements Runnable {

	private BlockingQueue<Integer> queue;
	private int nums = 20;
	private boolean isRunning = true;

	public Consumer() {
	}

	public Consumer(BlockingQueue<Integer> queue) {
		this.queue = queue;
	}

	public void run() {

		System.out.println("消费者开始消费");
		System.out.println("-------------------------");

		try {
			while (queue.size() > 0) {
				int data = (Integer) queue.take();
				Thread.sleep(500);// 休眠500毫秒
				System.out.println("消费者消费的数据是" + data);
			}

		} catch (Exception e) {
			e.printStackTrace();
			Thread.currentThread().interrupt();
		} finally {
			System.out.println("消费者线程退出!");
		}
	}
}
